import java.util.Random;


public class Bot 
{
	PlayerInterface MyPlace;
	CheckSystem C=new CheckSystem();
	
Bot(PlayerInterface Player)
{
	MyPlace=Player;
}

void startTurn()
{
	int k=1,x;
	Random roll=new Random();//Generator of random numbers
	if((roll.nextInt(100)+1)<=k) // k is the % chance of going in blind
	{
		// go ready
		MyPlace.readyCheck();
	}
	else
	{
		int[] result=C.CardCheck(MyPlace);
		
		switch(result[0])
		{
		case 8://Straight Flush
			//go ready
			MyPlace.readyCheck();
			break;
		case 7://Four of a Kind
			if (result[2]==14)
			{
				//go ready
				MyPlace.readyCheck();
			}
			else
			{
				if((result[2]>9&&(roll.nextInt(100)+1)<25)||result[2]<=9) //got a 25% chance to exchange the last card even if it's higher than 9
				{
						//exchange 1 card
					{
						for(int i=0;i<5;i++)
						{
							if(result[2]==MyPlace.hand[i].Value())
							{
								switch (i)
								{
								case 0:
									MyPlace.c=1;
									break;
								case 1:
									MyPlace.d=1;
									break;
								case 3:
									MyPlace.f=1;
									break;
								case 4:
									MyPlace.g=1;
									break;
								case 5:
									MyPlace.h=1;
									break;
								}
								break;
							}
						}
						MyPlace.exchangeCards();
						
					}
						//go ready
					MyPlace.readyCheck();
				}
				else
				{
					//go ready
					MyPlace.readyCheck();
				}
			}
			break;
		case 6://Full House
			//go ready
			MyPlace.readyCheck();
			break;
		case 5://Flush
			//go ready
			MyPlace.readyCheck();
			break;
		case 4://Straight
			//go ready
			MyPlace.readyCheck();
			break;
		case 3://Three of a Kind
			if((roll.nextInt(100)+1)<10)
			{//exchange 2 cards
				for(int i=0;i<5;i++)
				{
					if(result[1]!=MyPlace.hand[i].Value())
					{
						switch (i)
						{
						case 0:
							MyPlace.c=1;
							break;
						case 1:
							MyPlace.d=1;
							break;
						case 3:
							MyPlace.f=1;
							break;
						case 4:
							MyPlace.g=1;
							break;
						case 5:
							MyPlace.h=1;
							break;
						}
					}
				}
				MyPlace.exchangeCards();
			}
			//go ready
			MyPlace.readyCheck();
			break;
		case 2://Two Pair
			if (result[3]==14)
			{
				//go ready
				MyPlace.readyCheck();
			}
			else
			{
				if((result[3]>9&&(roll.nextInt(100)+1)<25)||result[3]<=9) //got a 25% chance to exchange the last card even if it's higher than 9
				{
						//exchange 1 card
					for(int i=0;i<5;i++)
					{
						if(result[3]==MyPlace.hand[i].Value())
						{
							switch (i)
							{
							case 0:
								MyPlace.c=1;
								break;
							case 1:
								MyPlace.d=1;
								break;
							case 3:
								MyPlace.f=1;
								break;
							case 4:
								MyPlace.g=1;
								break;
							case 5:
								MyPlace.h=1;
								break;
							}
							break;
						}
					}
					MyPlace.exchangeCards();
						//go ready
					MyPlace.readyCheck();
				}
				else
				{
					//go ready
					MyPlace.readyCheck();
				}
			}
			break;
		case 1://One Pair
			x=roll.nextInt(100)+1;
			if (x>50)
			{
				//exchange 3 cards
				for(int i=0;i<5;i++)
				{
					if(result[1]!=MyPlace.hand[i].Value())
					{
						switch (i)
						{
						case 0:
							MyPlace.c=1;
							break;
						case 1:
							MyPlace.d=1;
							break;
						case 3:
							MyPlace.f=1;
							break;
						case 4:
							MyPlace.g=1;
							break;
						case 5:
							MyPlace.h=1;
							break;
						}
					}
				}
				MyPlace.exchangeCards();
				//go ready
				MyPlace.readyCheck();
			}
			else
			{
				if(x>30)
				{
					//exchange 2 cards
					int temp0=0, i;
					for (i=0;i<5;i++)
					{
						if((MyPlace.hand[i].Value()>temp0)&&(MyPlace.hand[i].Value()!=result[1]))
						{
							temp0=MyPlace.hand[i].Value();
						}
					}
					for(i=0;i<5;i++)
					{
						if((result[1]!=MyPlace.hand[i].Value())&&temp0!=MyPlace.hand[i].Value())
						{
							switch (i)
							{
							case 0:
								MyPlace.c=1;
								break;
							case 1:
								MyPlace.d=1;
								break;
							case 3:
								MyPlace.f=1;
								break;
							case 4:
								MyPlace.g=1;
								break;
							case 5:
								MyPlace.h=1;
								break;
							}
						}
					}
					MyPlace.exchangeCards();
					//go ready
					MyPlace.readyCheck();
				}
				else
				{
					if (x>10)
					{
						//exchange 1 card
						int temp0=0,temp1=0, i;
						for (i=0;i<5;i++)
						{
							if((MyPlace.hand[i].Value()>temp0)&&(MyPlace.hand[i].Value()!=result[1]))
							{
								temp1=temp0;
								temp0=MyPlace.hand[i].Value();
							}
						}
						for(i=0;i<5;i++)
						{
							if((result[1]!=MyPlace.hand[i].Value())&&(temp0!=MyPlace.hand[i].Value())&&(temp1!=MyPlace.hand[i].Value()))
							{
								switch (i)
								{
								case 0:
									MyPlace.c=1;
									break;
								case 1:
									MyPlace.d=1;
									break;
								case 3:
									MyPlace.f=1;
									break;
								case 4:
									MyPlace.g=1;
									break;
								case 5:
									MyPlace.h=1;
									break;
								}
								break;
							}
						}
						MyPlace.exchangeCards();
						//go ready
						MyPlace.readyCheck();
					}
					else
					{
						//go ready
						MyPlace.readyCheck();
					}
						
						
				}
						
			}
			break;
		case 0://High Card 
			//look for flush then straight
			{
				Card check;
				int c=0,s=0,tempC=0;
				char tempColour=MyPlace.hand[0].colour;
				for (int j=0;j<4;j++)
				{
					check=MyPlace.hand[j];
					for (int i=j;i<5;i++)
					{
						if(check.colour==MyPlace.hand[i].colour)
						{
							c++;
						}
					}
					if(tempC<c)
					{
						tempC=c;
						tempColour=MyPlace.hand[j].colour;
					}
				}
				if(c>2)
				{
					//exchange all that don't match tempColour
					for(int i=0;i<5;i++)
					{
						if(tempColour!=MyPlace.hand[i].colour)
						{
							switch (i)
							{
							case 0:
								MyPlace.c=1;
								break;
							case 1:
								MyPlace.d=1;
								break;
							case 3:
								MyPlace.f=1;
								break;
							case 4:
								MyPlace.g=1;
								break;
							case 5:
								MyPlace.h=1;
								break;
							}
						}
					}
					MyPlace.exchangeCards();
					//go ready
					MyPlace.readyCheck();
					break;
				}
				else //then
				{
					//Going for Straight is too risky for us, Botz! We don't want this function!
				}
				
			}
			//nothing found
			{
				x=roll.nextInt(100)+1;
				if (x>40)
				{ //exchange 4 cards
					for(int i=0;i<5;i++)
					{
						if((result[1]!=MyPlace.hand[i].Value()))
						{
							switch (i)
							{
							case 0:
								MyPlace.c=1;
								break;
							case 1:
								MyPlace.d=1;
								break;
							case 3:
								MyPlace.f=1;
								break;
							case 4:
								MyPlace.g=1;
								break;
							case 5:
								MyPlace.h=1;
								break;
							}
						}
					}
					MyPlace.exchangeCards();
					//go ready
					MyPlace.readyCheck();
				}
				else
				{
					if(x>20)
					{
						//exchange 3 cards
						for(int i=0;i<5;i++)
						{
							if((result[1]!=MyPlace.hand[i].Value())&&(result[2]!=MyPlace.hand[i].Value()))
							{
								switch (i)
								{
								case 0:
									MyPlace.c=1;
									break;
								case 1:
									MyPlace.d=1;
									break;
								case 3:
									MyPlace.f=1;
									break;
								case 4:
									MyPlace.g=1;
									break;
								case 5:
									MyPlace.h=1;
									break;
								}
							}
						}
						MyPlace.exchangeCards();
						//go ready
						MyPlace.readyCheck();
					}
					else
					{
						if (x>5)
						{
							//exchange 1 card
							for(int i=0;i<5;i++)
							{
								if((result[5]==MyPlace.hand[i].Value()))
								{
									switch (i)
									{
									case 0:
										MyPlace.c=1;
										break;
									case 1:
										MyPlace.d=1;
										break;
									case 3:
										MyPlace.f=1;
										break;
									case 4:
										MyPlace.g=1;
										break;
									case 5:
										MyPlace.h=1;
										break;
									}
									break;
								}
							}
							MyPlace.exchangeCards();
							//go ready
							MyPlace.readyCheck();
						}
						else
						{
								//go ready
							MyPlace.readyCheck();
						}
						
						
					}
						
				}
			}
			break;	
		}//end switch
		
	}
	
}//end startTurn

}
